package user

import (
	"gitee.com/gopher2011/go-zero-gva/internal/svc"
	"gitee.com/gopher2011/go-zero-gva/internal/types"
)

func (l *User) GetUserList(req types.PageReq) (*types.Response, error) {
	var (
		total    int64
		userList []svc.User
	)
	limit := req.PageSize
	offset := req.PageSize * (req.Page - 1)
	if err := l.SvcCtx.DB.Model(&svc.User{}).Count(&total).Limit(limit).Offset(offset).Preload("Authority").Preload("Authorities").Find(&userList).Error; err != nil {
		return &types.Response{
			Code: 7,
			Msg:  "获取失败",
		}, nil
	}
	return &types.Response{
		Code: 0,
		Msg:  "获取成功",
		Data: svc.PageResult{
			List:     userList,
			Total:    total,
			Page:     req.Page,
			PageSize: req.PageSize,
		},
	}, nil
}
